import types from "./mutation-types";

const menu = {
    namespaced: true,
    state:{
        minLeftMenuWidth: 64,
        maxLeftMenuWidth: 250,
        isCollapse: false, // 菜单默认展开
        activeIndex: '',
        currentMenu: null,
    },
    getters: {
        menuWidth: state => {
            return state.isCollapse ? state.minLeftMenuWidth : state.maxLeftMenuWidth;
        },
        isCollapse: state => state.isCollapse,
        activeIndex: state => state.activeIndex,
        currentMenu: state => state.currentMenu,
    },
    mutations:{
        [types.SET_LEFT_COLLAPSE] (state, data) {  
            state.isCollapse = data
        },
        [types.SET_ACTIVE_INDEX] (state, data) {  
            state.activeIndex = data
        },
        [types.SET_CURRENT_MENU] (state, data) {  
            state.currentMenu = data
        }
    },
    actions:{
        setLeftCollapse:({ commit }, data) => {
            commit(types.SET_LEFT_COLLAPSE, data)
        },
        setActiveIndex:({ commit }, data) => {
            commit(types.SET_ACTIVE_INDEX, data)
        },
        setCurrentMenu:({ commit }, data) => {
            commit(types.SET_CURRENT_MENU, data)
        }
    }
    
}


export default menu;